package com.itheima.train.manager.order.mq;

import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * @program: itheima-train-manager-parent
 * @description:
 * @author: zhanghz001
 * @create: 2021-07-08 09:53
 **/
// @Component
public class ZhzOrderConsumer {
    // 创建日志对象
    private Logger log = LoggerFactory.getLogger(ZhzOrderConsumer.class);
    @Autowired
    private StringRedisTemplate redisTemplate;
    
    @RabbitListener(queues = {"delete_sorted_from_redis"})
    public void deleteSortedFromRedis(String msg, Channel channel, Message message) {
        //需要删除redis中的排队订单信息
        try {
            log.info("删除redis中订单排队的信息开始---->{}", msg);
            
            redisTemplate.boundZSetOps("train_manager:sorted_queue").remove(msg);
            
            log.info("删除redis中订单排队的信息结束---->{}", msg);
            
            //手动应答
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        } catch (Exception e) {
            e.printStackTrace();
            log.info("删除redis中订单排队的信息异常---->{}", msg);
            
        }
        
    }
}
